var snow;
(function (snow_1) {
    // 雪花
    var Snowflake = /** @class */ (function () {
        function Snowflake() {
            this.speed = random(0, 1);
            this.x = random(random(1, 100), random(1, 100));
            this.y = -10;
            this.size = random(10, 50);
            this.init();
        }
        Snowflake.prototype.move = function () {
            this.y = this.y + this.speed;
            if (this.y > 100) {
                this.y = -10;
            }
            this.ele.style.top = this.y + '%';
        };
        Snowflake.prototype.init = function () {
            var img = document.createElement('img');
            img.src = './img/snow.png';
            img.style.height = this.size + 'px';
            img.style.position = 'absolute';
            img.style.left = this.x + '%';
            img.style.top = this.y + '%';
            this.ele = img;
        };
        Snowflake.prototype.show = function () {
            this.move();
            return this.ele;
        };
        return Snowflake;
    }());
    var Screen = /** @class */ (function () {
        function Screen(parameters) {
            this.init();
        }
        Screen.prototype.init = function () {
            var root = document.createElement('main');
            root.className = 'root';
            root.style.background = "url('./img/snow-night.jpg') center/cover no-repeat";
            this.root = root;
            document.body.appendChild(this.root);
        };
        Screen.prototype.render = function (snows) {
            // this.root.innerHTML = snows.map(snow => {
            //   return snow.show().outerHTML
            // }).join('')
            this.root.appendChild(snows.show());
        };
        return Screen;
    }());
    function createScreen(params) {
        var instance;
        return (function () {
            if (instance) {
                return instance;
            }
            return new Screen(params);
        })();
    }
    function random(min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }
    var screen = createScreen();
    var snows = [];
    for (var i = 0; i < 20; i++) {
        snows.push(new Snowflake());
    }
    function main() {
        snows.forEach(function (snow) {
            screen.render(snow);
        });
        window.requestAnimationFrame(main);
    }
    window.requestAnimationFrame(main);
})(snow || (snow = {}));
